package com.cl.service;

import com.cl.dto.ResultDTO;
import com.cl.entity.WorkLoad;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.OutputStream;

import com.cl.entity.WorkLoad;

/**
 * Created by Administrator on 2015/6/30.
 */
@Service
public class ExcelService {

    @Autowired
    private CommonService commonService;

    /**
     *
     * @param out
     * @param filter
     */
    public void WLOutExcel(OutputStream out, String filter) {
        ResultDTO dto = commonService.getWorkLoadEntities(filter);
        if (dto != null && dto.data != null && dto.data.size() > 0) {
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("工作量统计");// 创建工作表单
            HSSFRow header = sheet.createRow((short) 0);
            HSSFCell xhCell = header.createCell(0);
            xhCell.setCellValue(new HSSFRichTextString("序号"));
            HSSFCell userNameCell = header.createCell(1);
            userNameCell.setCellValue(new HSSFRichTextString("用户名"));
            HSSFCell numCell = header.createCell(2);
            numCell.setCellValue(new HSSFRichTextString("稿数"));
            for(int i=0;i<dto.data.size();i++) {
                WorkLoad obj = (WorkLoad)(dto.data.get(i));
                HSSFRow row = sheet.createRow((short) (i+1));
                HSSFCell xhRCell = row.createCell(0);
                xhRCell.setCellValue(obj.id);
                HSSFCell userNameRCell = row.createCell(1);
                userNameRCell.setCellValue(new HSSFRichTextString(obj.userName));
                HSSFCell numRCell = row.createCell(2);
                numRCell.setCellValue(obj.num);
            }
            try {
                wb.write(out);
            } catch (IOException e) {

            }
        }
    }

}
